package com.zsc.wxm.ysh.anjo.house.controller;


import com.zsc.wxm.ysh.anjo.house.service.ImagesService;
import com.zsc.wxm.ysh.anjo.result.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author playmaker
 * @since 2021-01-04
 */
@RestController
@RequestMapping("/house/images")
public class ImagesController {

    @Resource
    private ImagesService imagesService;


    @PostMapping("/upload-images")
    @ApiOperation("上传房源图片")
    public Result uploadImages(@RequestParam("resourcesId") Long resourcesId, @RequestParam("files") MultipartFile[] files) {
        imagesService.upload(resourcesId, files);
        return Result.ok("上传成功");
    }

    @PostMapping("/list")
    @ApiOperation("根据房源id获取图片")
    public Result list(@RequestParam("resourcesId") Long resourcesId) {
        Map<String, Object> data = new HashMap<>();
        data.put("data", imagesService.list(resourcesId));
        return Result.ok("获取成功", data);
    }

}

